/*
 * Module NAME:    rfcomm_types.h
 * PROJECT CODE:   
 * DESCRIPTION:    RFCOMM Types
 * MAINTAINER:     David Airlie
 * DATE:           14 Jan 2000
 *
 * SOURCE CONTROL: $Id: rfcomm_types.h,v 1.1.1.1 2007/12/18 05:32:40 tianwq Exp $
 *
 * LICENSE:
 *     This source code is copyright (c) 2001-2002 RDA Microelectronics, Ltd.
 *     All rights reserved.
 *
 * REVISION HISTORY:
 * 
 * SOURCE:
 *
 * ISSUES:
 *
 * NOTES TO USERS:
 * 
 */
#ifndef RDABT_RFCOMM_TYPES_H
#define RDABT_RFCOMM_TYPES_H

#include "bt_types.h"
#include "host_buf.h"

/* Internal RFCOMM types */
typedef u_int8 rdabt_t_rfcomm_accept;

#define RDABT_RFCOMM_REFUSE 0
#define RDABT_RFCOMM_ACCEPT 1

typedef u_int8 rdabt_t_rfcomm_dlci;
typedef u_int16 rdabt_t_rfcomm_cid;
typedef u_int8 rdabt_t_rfcomm_schan;

typedef enum {
  RDABT_RFCOMM_CB_CFM,
  RDABT_RFCOMM_CB_IND
} rdabt_t_rfcomm_cb_type;

typedef enum {
    RFDS5, 
    RFDS7, 
    RFDS6, 
    RFDS8 
} rdabt_t_rfcomm_data_bits;

typedef enum { 
    RF2400, 
    RF4800, 
    RF7200, 
    RF9600, 
    RF19200, 
    RF38400, 
    RF57600, 
    RF115200, 
    RF230400 
} rdabt_t_rfcomm_port_speed;

typedef enum { 
    RFSTOP1, 
    RFSTOP15 
} rdabt_t_rfcomm_stop_bits;

typedef enum { 
    RFNONE, 
    RFPARENB 
} rdabt_t_rfcomm_parity;

typedef enum { 
    RFODD, 
    RFEVEN, 
    RFMARK, 
    RFSPACE 
} rdabt_t_rfcomm_paritytype;

typedef enum {
  RDABT_RFCOMM_FLOW_DATA_STOP,
  RDABT_RFCOMM_FLOW_DATA_GO
} rdabt_t_rfcomm_flow_state;

/* RFCOMM Start - Ref TS 07.10 5.1.2 */
struct RDABT_RFCOMM_start_sys_params 
{
  /* From reading of RFCOMM spec + TS07.10, not need anything except below */
  /* Port Speed from the enum */
  rdabt_t_rfcomm_port_speed port_speed;
  
  /* Max Frame Size 1-128 for RFCOMM, Default: 31 */
  u_int16 max_frame_size;
  /* Request credit based flow from the peer */
  u_int8 enable_credit_flow_control; 
};
typedef struct RDABT_RFCOMM_start_sys_params rdabt_t_rfcomm_start_sys_params;

/* RFCOMM DLC Parameters - Ref TS 07.10 5.1.8.1.1 */
struct RDABT_RFCOMM_dlc_params
{
  /* priority seems unused in RFCOMM */
  /* Maximum Frame Size 1-32768, Default: 31 */
  u_int16 max_frame_size;
  u_int8 credit_flow_enabled;
  u_int8 local_credits;
  u_int8 peer_credits;
};
typedef struct RDABT_RFCOMM_dlc_params rdabt_t_rfcomm_dlc_params;

/* defines for flow mask in port parameters */
#define RDABT_RPN_FLOW_INPUT_XONXOFF 0x01
#define RDABT_RPN_FLOW_OUTPUT_XONXOFF 0x02
#define RDABT_RPN_FLOW_INPUT_RTR 0x04
#define RDABT_RPN_FLOW_OUTPUT_RTR 0x08
#define RDABT_RPN_FLOW_INPUT_RTC 0x10
#define RDABT_RPN_FLOW_OUTPUT_RTC 0x20

/* defines for parameter mask in port parameters */
#define RDABT_RFCOMM_CC_RPN_PM_BITRATE 0x0001
#define RDABT_RFCOMM_CC_RPN_PM_DATABITS 0x0002
#define RDABT_RFCOMM_CC_RPN_PM_STOPBITS 0x0004
#define RDABT_RFCOMM_CC_RPN_PM_PARITY 0x0008
#define RDABT_RFCOMM_CC_RPN_PM_PARITY_TYPE 0x0010
#define RDABT_RFCOMM_CC_RPN_PM_XON_CH 0x0020
#define RDABT_RFCOMM_CC_RPN_PM_XOFF_CH 0x0040
#define RDABT_RFCOMM_CC_RPN_PM_RESV1 0x0080
#define RDABT_RFCOMM_CC_RPN_PM_XONXOFF_INPUT 0x0100
#define RDABT_RFCOMM_CC_RPN_PM_XONXOFF_OUTPUT 0x0200
#define RDABT_RFCOMM_CC_RPN_PM_RTR_INPUT 0x0400
#define RDABT_RFCOMM_CC_RPN_PM_RTR_OUTPUT 0x0800
#define RDABT_RFCOMM_CC_RPN_PM_RTC_INPUT 0x1000
#define RDABT_RFCOMM_CC_RPN_PM_RTC_OUTPUT 0x2000

/* RFCOMM Port Parameters - Ref TS 07.10 5.1.8.2.1 */
struct RDABT_RFCOMM_port_parameters {
  rdabt_t_rfcomm_port_speed port_speed;
  rdabt_t_rfcomm_data_bits data_bits;
  rdabt_t_rfcomm_stop_bits stop_bits;
  rdabt_t_rfcomm_parity parity_enable;
  rdabt_t_rfcomm_paritytype paritytype;
  u_int16 param_mask;
  u_int8 flow_mask;
  /* Need to add an xon/xoff char */
  u_int8 xon;
  u_int8 xoff;
};
typedef struct RDABT_RFCOMM_port_parameters rdabt_t_rfcomm_port_params;

/* RFCOMM Modem Signal - Ref TS 07.10 5.1.8.2.2 */

/* DTR/DSR -> RTC, RTSCTS -> RTR, RI->IC, DCD->DV, p392 RFCOMM */
#define RDABT_RFCOMM_MSC_DTRDSR 1
#define RDABT_RFCOMM_MSC_RTSCTS 2
#define RDABT_RFCOMM_MSC_RI 4
#define RDABT_RFCOMM_MSC_DCD 8

typedef u_int8 rdabt_t_rfcomm_modem_signal;

/* RFCOMM Control Parameters - Ref TS 07.10 5.1.8.2.2 */
struct RDABT_RFCOMM_control_parameters {
  rdabt_t_rfcomm_modem_signal modem_signal;
  u_int8 break_signal;
  rdabt_t_rfcomm_flow_state flow_state;
};
typedef struct RDABT_RFCOMM_control_parameters rdabt_t_rfcomm_control_params;

/* RFCOMM Line Status Parameters - Ref TS 07.10 5.1.8.2.3 */

#define RDABT_RFCOMM_LSTAT_NO_ERROR 0
#define RDABT_RFCOMM_LSTAT_ERROR 1
#define RDABT_RFCOMM_LSTAT_OVERRUN_ERROR 2 
#define RDABT_RFCOMM_LSTAT_PARITY_ERROR 4
#define RDABT_RFCOMM_LSTAT_FRAMING_ERROR 8

typedef unsigned int rdabt_t_rfcomm_line_stat_params;

#define RDABT_RFCOMM_PN_CREDIT_FLOW_REQ 0x0F
#define RDABT_RFCOMM_PN_CREDIT_FLOW_RESP 0x0E

/* 
 * Call back structures for a DLC instance 
 * Current callbacks are for
 * DLC Establishment Confirmation
 * Data Indications
 * DLC Release Ind
 * Port Negotitaion Ind
 * Control Ind
 * Line Status Ind
 * Flow Ind
 */
struct rdabt_rfcomm_dlc_cb {
  t_api (*dlc_estab_ind)(t_bdaddr bd_addr, rdabt_t_rfcomm_dlci dlci, rdabt_t_rfcomm_dlc_params *dlc_params, void *multi_inst);
 t_api (*dlc_estab_conf)(t_bdaddr bd_addr, rdabt_t_rfcomm_dlci dlci, rdabt_t_rfcomm_dlc_params *dlc_params, rdabt_t_rfcomm_accept accept, void *multi_inst);
  t_api (*dlc_data_ind)(rdabt_t_rfcomm_dlci DLCI, rdabt_host_buf_t *buffer, void *multi_inst);
  t_api (*dlc_rel_ind)(rdabt_t_rfcomm_dlci DLCI, void *multi_inst);
  t_api (*portneg)(rdabt_t_rfcomm_dlci DLCI, rdabt_t_rfcomm_port_params *port_params, void *multi_inst, rdabt_t_rfcomm_cb_type cbtype);
  t_api (*control)(rdabt_t_rfcomm_dlci DLCI, rdabt_t_rfcomm_control_params *ctrl_params, void *multi_inst, rdabt_t_rfcomm_cb_type cbtype);
  t_api (*linestat)(rdabt_t_rfcomm_dlci, rdabt_t_rfcomm_line_stat_params ls_params, void *multi_inst, rdabt_t_rfcomm_cb_type cbtype);
  t_api (*agg_flow_ind)(rdabt_t_rfcomm_dlci DLCI, rdabt_t_rfcomm_flow_state state, void *multi_inst);  
  t_api (*dlc_paramneg)(rdabt_t_rfcomm_dlci DLCI, rdabt_t_rfcomm_dlc_params *dlc_params, void *multi_inst, rdabt_t_rfcomm_cb_type cbtype);
  t_api (*credit_flow_ind)(rdabt_t_rfcomm_dlci DLCI, rdabt_t_rfcomm_flow_state state, void *multi_inst);
};


struct rdabt_rfcomm_multi_cb {
  t_api (*rfstart_conf)(t_bdaddr bd_addr, rdabt_t_rfcomm_start_sys_params *system_parameters, rdabt_t_rfcomm_accept accept, void *multi_inst);
  t_api (*close_ind)(void);

};

struct rfcomm_timer_multi_cb    //only for timer using add by xzc
{
  t_api (*rfstart_conf)(t_bdaddr bd_addr, rdabt_t_rfcomm_start_sys_params *system_parameters, rdabt_t_rfcomm_accept accept, void *multi_inst);
  t_bdaddr bd_addr;
  rdabt_t_rfcomm_start_sys_params *system_parameters;
  rdabt_t_rfcomm_accept accept;
  void *multi_inst;
};

#endif
